import request from '@/utils/request'

// 获取文件上传令牌
export function getUploadToken(data) {
  return request({
    url: '/file/token',
    method: 'post',
    data: data,
    headers: { 'repeatSubmit': false }
  })
}

// 上传成功回调
export function uploadCallback(data) {
  return request({
    url: '/file/uploadCallback',
    method: 'post',
    data: data
  })
}

// 传统文件上传（通过后端）
export function uploadFile(data) {
  return request({
    url: '/file/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data',
      'repeatSubmit': false
    }
  })
}

// 获取文件访问URL
export function getFileUrl(params) {
  return request({
    url: '/file/url',
    method: 'get',
    params: params
  })
}

// 删除文件
export function deleteFile(data) {
  return request({
    url: '/file/delete',
    method: 'delete',
    data: data
  })
}

// 分片上传（带错误处理控制）
export function uploadChunk(data, options = {}) {
  const { skipErrorHandler = true } = options
  
  return request({
    url: '/file/chunk/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data',
      'repeatSubmit': false,
      'skipErrorHandler': skipErrorHandler
    },
    timeout: 60000 // 60秒超时
  })
}